<template>
  <view class="user-info">
    <view class="info-head">
      <view class="head-img">
        <image :src="userInfo ? userInfo.avatar:''" mode=""></image>
      </view>
      <view class="head-name">{{userInfo?userInfo.name:''}}</view>
      <view class="head-btn" v-if="!userInfo.permission">
        <button class="followed-not" v-if="!isSollowed" @click="onFollowed">
          <up-icon color="#fff" size="32rpx" name="plus"></up-icon>关注
        </button>
        <button class="followed-already" v-else @click="onFollowed">已关注</button>
      </view>
    </view>
    <view class="brief-introduction">
      <view ref="textRef" :class="['text-cont',btnFlag ?'text-unfold':'text-collapse']">
        <view class="unfold-and-collapse" @click="btnFlagfn" v-if="!userInfo.permission">
          {{!btnFlag ?"展开" :"收起"}}
          <up-icon color="#FF416C" :name="!btnFlag ? 'arrow-down' :'arrow-up'"></up-icon>
        </view>
        <view class="text-content">
          简介：{{userInfo.desc?userInfo.desc :text}}
          <up-icon name="edit-pen" class="text-edit" v-if="userInfo.permission" @click="modalShow = true"></up-icon>
        </view>
      </view>
    </view>
    <up-popup :show="modalShow" mode="center" round="32rpx" @close="modalShow= false">
      <view class="introduction-edit">
        <view class="edit-region">
          <view class="edit-title">编辑简介</view>
          <view class="edit-text">
            <up-textarea v-model="userInfo.desc" height="240rpx" placeholder="请输入简介内容"></up-textarea>
          </view>
        </view>
        <view class="edit-btn">
          <view class="btn-close" @click="modalShow= false">取消</view>
          <view class="btn-confirm" @click="onConfirm">确认</view>
        </view>
      </view>
    </up-popup>
  </view>

</template>

<script setup>
  import {
    ref,
    reactive,
    toRefs,
    defineProps,
    defineEmits
  } from 'vue'
  const {permission,isSollowed,userInfo} = defineProps({
    permission: {
      type: Boolean,
      default: true
    },
    isSollowed: {
      type: Boolean,
      default: false
    },
    userInfo: {
      type: Object,
      default: {}
    }
  })
  const introductionText = ref('')
  const followedShow = ref(false)
  const modalShow = ref(false)
  const introduce = reactive({
    text: '设计师在摸鱼没有留下什么作品~',
    btnFlag: false,
  })
  const emit = defineEmits(['confirm'])

  function btnFlagfn() {
    introduce.btnFlag = !introduce.btnFlag
  }

  function onFollowed() {
    userInfo.followedShow = !userInfo.followedShow
  }

  function onConfirm() {
    emit('confirm', user)
  }
  const {
    text,
    btnFlag
  } = toRefs(introduce)
</script>

<style lang="less" scoped>
  .user-info {
    width: 100%;
    display: flex;
    flex-direction: column;

    .info-head {
      display: flex;
      align-items: center;
      justify-content: space-between;

      .head-img {
        width: 100rpx;
        height: 100rpx;
        border-radius: 50rpx;

        image {
          width: 100rpx;
          height: 100rpx;
          border-radius: 50rpx;
        }

      }

      .head-name {
        margin-left: 20rpx;
        flex: 1;
        font-size: 44rpx;
        font-weight: 500;
        letter-spacing: 0rpx;
        color: rgba(51, 51, 51, 1);

      }

      .head-btn {
        width: 160rpx;
        height: 64rpx;

        .followed-not {
          display: flex;
          width: 160rpx;
          height: 64rpx;
          border-radius: 122rpx;
          background: #FF416C;
          font-size: 28rpx;
          font-weight: 400;
          line-height: 40rpx;
          color: rgba(255, 255, 255, 1);
          align-items: center;
          justify-content: center;
        }

        .followed-already {
          width: 160rpx;
          height: 64rpx;
          border-radius: 122rpx;
          background: #E6E6E6;
          font-size: 28rpx;
          font-weight: 400;
          line-height: 64rpx;
          color: rgba(51, 51, 51, 1);
          text-align: center;

        }
      }
    }

    .brief-introduction {
      display: flex;
    }

    .text-cont {
      width: 100%;
      margin: 40rpx auto 0;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      overflow: hidden;
      text-align: left;
    }

    .text-unfold {
      -webkit-line-clamp: 9999;
    }

    .text-collapse {
      -webkit-line-clamp: 2;
    }

    .text-content {
      display: flex;
      align-items: center;

      .text-edit {
        margin-left: 36rpx;
      }
    }

    .unfold-and-collapse {
      display: flex;
      color: #010101;
      float: right;
      clear: both;
      margin-right: 20rpx;
      font-size: 24rpx;
      font-weight: 400;
      line-height: 40rpx;
      color: rgba(255, 65, 108, 1);
      align-items: center;
    }

    .text-cont::before {
      content: '';
      float: right;
      width: 0;
      height: calc(100% - 32rpx);
    }
  }

  .introduction-edit {
    border-radius: 32rpx;
    width: 622rpx;
    min-height: 500rpx;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background-color: #fff;

    .edit-region {
      width: 100%;
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      box-sizing: border-box;
      padding: 48rpx;

      .edit-title {
        font-size: 32rpx;
        font-weight: 500;
        color: rgba(51, 51, 51, 1);
      }

      .edit-text {
        width: 100%;
        margin-top: 16rpx;
      }
    }

    .edit-btn {
      width: 100%;
      height: 96rpx;
      display: flex;

      view {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 32rpx;
        font-weight: 400;
      }

      .btn-close {
        color: #333333;
      }

      .btn-confirm {
        color: #FF416C;
      }
    }
  }
</style>